#include "sellingstate.h"

#include <qDebug>

SellingState::SellingState(GumballMachine *machine)
    : m_machine(machine)
{
}

void SellingState::insertQuarter()
{
    qDebug() << "sorry, you can not insert a quarter, due to selling!";
}

void SellingState::ejectQuarter()
{
    qDebug() << "sorry, you can not insert a quarter, due to selling!";
}

void SellingState::turnCrank()
{
    qDebug() << "sorry, you can not insert a quarter, due to selling!";
}

void SellingState::dispense()
{
    if (m_machine)
    {
        m_machine->releaseGumBall();
        if (m_machine->getCount() > 0)
        {
            m_machine->setState(m_machine->getNoQuarterState());
        }
        else
        {
            m_machine->setState(m_machine->getSoldOutState());
        }
    }
}
